package com.shoesmail.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shoesmail.domain.dto.ShoesListDto;
import com.shoesmail.domain.vo.JsonResultVo;
import com.shoesmail.domain.vo.PageResult;
import com.shoesmail.domain.vo.user.UserShoesVo;
import com.shoesmail.mapper.ShoeMapper;
import com.shoesmail.service.UserShoesService;
import com.shoesmail.utils.PhotoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：CDB
 * @description：TODO
 * @date ：2025/9/19 9:48
 */
@Service
public class UserShoesServiceImpl implements UserShoesService {


    @Autowired
    private ShoeMapper shoeMapper;

    @Autowired
    private PhotoUtil photoUtil;
    @Override
    public JsonResultVo<PageResult<UserShoesVo>> getShoesList(int pageOrder, int pageNum) {
        PageHelper.startPage(pageOrder,pageNum);
        List<ShoesListDto> shoes = shoeMapper.getShoes();
        List<UserShoesVo> shoesVos  = new ArrayList<>();

        for(ShoesListDto shoe:shoes){
            UserShoesVo shoesVo = new UserShoesVo();
            int categoryId = shoe.getCategoryId();
            int brandId = shoe.getBrandId();
            String photoUrl = photoUtil.getPhotoUrl(brandId, categoryId, 0);

            shoesVo.setId(shoe.getId());
            shoesVo.setCategory(shoe.getCategoryName());
            shoesVo.setBrand(shoe.getBrandName());
            shoesVo.setPhotoUrl(photoUrl);
            shoesVo.setName(shoe.getName());
            shoesVo.setPrice(shoe.getPrice());
            shoesVo.setSales(shoe.getSales());
            shoesVos.add(shoesVo);
        }

        PageInfo<ShoesListDto> page = new PageInfo<>(shoes);
        PageResult<UserShoesVo> userShoesVoPageInfo = new PageResult<>(page,shoesVos);

        return JsonResultVo.success("成功",userShoesVoPageInfo);
    }
}







